; Author => Abdallah Mohamed ( 0xNinjaCyclone )

.386
.MODEL flat, c
.code

GrabRetAddresses proc    
	mov edx, [esp + 4]       ; param1: Where the results will be stored
	mov ecx, [esp + 8]       ; param2: Number of addresses to read
	xor eax, eax             ; bSuccess = FALSE
	mov ebx, ebp             ; BP
	grab:
	dec ecx                  ; dwSize--
	mov esi, [ebx]           ; Previous BP
	mov edi, [ebx + 4]       ; Return Address
	test esi, esi            ; We have to stop if we reach the stack base
	jz finish
	mov [edx + ecx * 4], edi ; pResult[dwSize] = pRetAddr;
	mov ebx, esi             ; Bring down to the next stack frame
	test ecx, ecx            ; Stop if we completed our task
	jnz grab
	inc eax                  ; bSuccess = TRUE
	finish:
	ret                      ; return to the caller
GrabRetAddresses endp 

end